package com.rjkj.medicalwaste.ui.blue

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import com.rjkj.medicalwaste.R
import com.rjkj.medicalwaste.base.BaseFragment
import com.rjkj.medicalwaste.databinding.FragmentDeviceDataTestBinding
import com.rjkj.medicalwaste.viewmodels.BluetoothControlViewModel
import kotlinx.coroutines.delay

class DeviceDataTestFragment : BaseFragment<FragmentDeviceDataTestBinding>() {
    private val bluetoothControlViewModel: BluetoothControlViewModel by activityViewModels()

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View {
        val binding  = FragmentDeviceDataTestBinding.inflate(inflater,container,false)
        binding.lifecycleOwner = viewLifecycleOwner
        binding.testData = bluetoothControlViewModel
        onSubscribeUi(binding)

        return binding.root
    }

    override fun onSubscribeUi(binding: FragmentDeviceDataTestBinding) {
        binding.result.setOnClickListener {
            bluetoothControlViewModel.startRec()
        }
        binding.print.setOnClickListener {
//            bluetoothControlViewModel.printRec()
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        bluetoothControlViewModel.stopRec()
    }

}